package com.eDrive;


import javax.xml.parsers.SAXParser;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import javax.xml.parsers.SAXParserFactory;

/**
 * Here is sample of reading attributes of a given XML element.
 */

public class SampleOfReadingAttributes {
    /**
     * Application entry point
     * @param args command-line arguments
     */
    public static void main(String[] args) {
        try {
            // creates and returns new instance of SAX-implementation:
            SAXParserFactory factory = SAXParserFactory.newInstance();
            
            // create SAX-parser...
            SAXParser parser = factory.newSAXParser();
            // .. define our handler:
            SaxHandler handler = new SaxHandler();
            
            // and parse:
            parser.parse("rit naar station.xml", handler);
            
        } catch (Exception ex) {
            ex.printStackTrace(System.out);
        }
    }
    
    /**
     * Our own implementation of SAX handler reading
     * a purchase-order data.
     */
    private static final class SaxHandler extends DefaultHandler {
        
        // we enter to element 'qName':
        public void startElement(String uri, String localName,
                String qName, Attributes attrs) throws SAXException {
            
            if (qName.equals("Wpt")) {
                // order date value as String:
                String latitude = attrs.getValue("lat");
                // order number as a String:
                String longitude = attrs.getValue("long");
                String speed = attrs.getValue("speed");
                String efficiency = attrs.getValue("eff");
                String effLabel = attrs.getValue("effL");
                String time = attrs.getValue("t");
                
                
                //System.out.println("Lat: " + latitude +" Long is: " +longitude +" Speed is: "+speed +" Efficiency is: "+efficiency +" Efficiency Label is: "+effLabel +" Time is: "+time);
                
            }
        }
    }
}